package com.tuangou.tuangouorder.order.controller;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;
import com.tuangou.tuangouorder.order.entity.GroupGoodsEntity;
import com.tuangou.tuangouorder.order.service.GroupGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @author lsy
 * @email lsy@tuangou.com
 * @date 2021-06-18 20:36:33
 */
@RestController
@RequestMapping("order/groupgoods")
public class GroupGoodsController {
    @Autowired
    private GroupGoodsService groupGoodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:groupgoods:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = groupGoodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{groupId}")
    //@RequiresPermissions("order:groupgoods:info")
    public R info(@PathVariable("groupId") Integer groupId){
		GroupGoodsEntity groupGoods = groupGoodsService.getById(groupId);

        return R.ok().put("groupGoods", groupGoods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:groupgoods:save")
    public R save(@RequestBody GroupGoodsEntity groupGoods){
		groupGoodsService.save(groupGoods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:groupgoods:update")
    public R update(@RequestBody GroupGoodsEntity groupGoods){
		groupGoodsService.updateById(groupGoods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:groupgoods:delete")
    public R delete(@RequestBody Integer[] groupIds){
		groupGoodsService.removeByIds(Arrays.asList(groupIds));

        return R.ok();
    }

}
